package com.itqn.servlet;

import com.itqn.pojo.Employee;
import com.itqn.service.EmployeeService;
import com.itqn.service.Impl.EmployeeServiceImpl;
import lombok.SneakyThrows;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value = "/employeeDisableServlet")
public class employeeDisableServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @SneakyThrows
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //解决中文乱码问题
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html; charset=UTF-8");

        //获取参数
        String id = request.getParameter("id");
        String status = request.getParameter("status");

        //创建实体类对象
        Employee employee=new Employee();
        employee.setId(Long.valueOf(id));
        employee.setStatus(Integer.valueOf(status));

        //创建业务逻辑层对象
        EmployeeService employeeService=new EmployeeServiceImpl();
        Integer result = employeeService.disable(employee);
        PrintWriter writer = response.getWriter();
        writer.write(result>0?"ok":"no");

    }
}
